<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="multipart/form-data">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>用户管理后台</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="css/pintuer.css">
    <link rel="stylesheet" href="css/admin.css">
    <script src="js/jquery.js"></script>
    <script src="layui/layui.js"></script>
    <script src="js/admin.js"></script>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">皮皮虾小魔仙后台</div>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <img src="images/bid_new.gif" class="layui-nav-img">${name}
            </li>
            <li class="layui-nav-item"><a href="index.jsp" target="_top" id="out">退出</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <ul class="layui-nav layui-nav-tree"  lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">查看订单</a>
                    <dl class="layui-nav-child">
                        <dd><a onclick="allorders()">所有订单</a></dd>
                        <dd><a onclick="unisokorders()">未确认订单</a></dd>
                        <dd><a onclick="isokorders()">已确认订单</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item layui-nav-itemed">
                    <a href="javascript:;">商品查看</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;" onclick="goodshow(0)">所有商品</a></dd>
                        <dd><a href="javascript:;" onclick="goodshow(1)">美食</a></dd>
                        <dd><a href="javascript:;" onclick="goodshow(2)">饮品</a></dd>
                        <dd><a href="javascript:;" onclick="goodshow(3)">水果</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item"><a href="javascript:;" onclick="userset()">账户管理</a></li>
                <li class="layui-nav-item"><a href="admin_goods.jsp">发布商品</a></li>
            </ul>
        </div>
    </div>

    <div class="layui-body" id="main_are" style="text-align: center">
        <table class="table table-hover text-center" style="text-align: center;font-size: 15px" border="1" id="goodstable">
            <tr>
                <th style="width: 50px">姓名</th>
                <th style="width: 50px">用户名</th>
                <th style="width: 50px">密码</th>
                <th style="width: 200px">地址</th>
                <th style="width: 100px">电话</th>
                <th style="width: 50px">性别</th>
                <th style="width: 100px">描述</th>
                <th style="width: 80px">账户类型</th>
                <th style="width: 150px">操作</th>
            </tr>
            <c:forEach items="${userList}" var="user">
                <form action="update_user.do" method="post" id="up_user_form_${user.user_id}">
                    <input name="user_id" type="hidden" value="${user.user_id}">
                    <input name="role_id" type="hidden" value="${user.role_id}">
                    <tr style="text-align: center">
                        <td><input type="text" name="name" value="${user.name}" id="name_${user.user_id}" size="10" style="border: none;text-align: center"></td>
                        <td><input type="text" name="username"  value="${user.username}" id="username_${user.user_id}" size="10"  style="border: none;text-align: center"></td>
                        <td><input type="text" name="password"  value="${user.password}" id="password_${user.user_id}" size="10"  style="border: none;text-align: center"></td>
                        <td><input type="text" name="address"  value="${user.address}" id="address_${user.user_id}" size="35"  style="border: none;text-align: center"></td>
                        <td><input type="text" name="tel" value="${user.tel}" id="tel_${user.user_id}" size="20"  style="border: none;text-align: center"></td>
                        <td><input type="text" name="sex"  value="${user.sex}" id="sex_${user.user_id}" size="5"  style="border: none;text-align: center"></td>
                        <td><input type="text" name="discrib"  value="${user.discrib}" id="discrib_${user.user_id}" size="25"  style="border: none;text-align: center"></td>
                        <td>
                            <c:if test="${user.role_id==1}">管理员</c:if>
                            <c:if test="${user.role_id==0}">普通用户</c:if>
                        </td>
                        <td>
                            <button type="button" class="layui-btn" onclick="up_user_form(${user.user_id})">修改</button>
                            <button type="button" class="layui-btn" style="color: red" onclick="ckeck_user_del(${user.user_id})" id="del_${user.user_id}">删除</button>
                        </td>
                    </tr>
                </form>
            </c:forEach>
        </table>
    </div>
    <div class="layui-footer">
        © 皮皮虾小魔仙外卖.com
    </div>
</div>
</body>
<script>
    var websocket=null;
    if('WebSocket' in window){
        websocket=new WebSocket('ws://localhost:8080<%=path%>/webSocket');
    }else{
        alert("该浏览器不支持websocket");
    }
    websocket.onopen=function (event) {
        console.log('建立链接');
    }
    websocket.onclose=function (event) {
        console.log('链接关闭');
    }
    websocket.onmessage=function (event) {
        console.log('收到消息'+event.data)
        //消息提醒
        layer.confirm("你有新的订单", {
                but: ['我看看', '懒得看'],}
            ,function () {
                $.ajax({
                    url: "unisokorders.do",
                    type: "POST",
                    success: function () {
                        window.location.href = "admin.jsp";
                    }
                })
            }
        );
    }
    websocket.onerror=function (event) {
        alert("发生错误");
    }
    window.onbeforeunload=function () {
        websocket.close();
    }
    function up_user_form(thisid){
        var tempform="up_user_form_"+thisid;
        var tempaname="name_"+thisid;
        var tempusername="username_"+thisid;
        var temppassword="password_"+thisid;
        var tempaddress="address_"+thisid;
        var temptel="tel_"+thisid;
        var tempsex="sex_"+thisid;
        var tempdiscrib="discrib_"+thisid;
        var name=$("#"+tempaname).val();
        var username=$("#"+tempusername).val();
        var password=$("#"+temppassword).val();
        var address=$("#"+tempaddress).val();
        var sex=$("#"+tempsex).val();
        var tel=$("#"+temptel).val();
        var discrib=$("#"+tempdiscrib).val();
        if(name==''||name==null)
            alert("请输入姓名");
        else if(username==''||username==null)
            alert("请输入用户名");
        else if(password==''||password==null)
            alert("请输入密码");
        else if(address==''||address==null)
            alert("请输入地址");
        else if(sex==''||sex==null)//||(sex!="男")||(sex!="女")
            alert("性别暂时只支持男或女哈");
        else if(tel==''||tel==null)
            alert("请输入电话");
        else if(discrib==''||discrib==null)
            alert("请输入描述");
        else{
            $("#"+tempform).submit();
            if(thisid==1){
                if(username!=${user.username}||password!=${user.password}){
                    $.ajax({
                        url:"exit.do",
                        type:"POST",
                    })
                    alert("管理员账户已修改，请重新登录");
                    window.location.href="login.jsp";
                }
            }
        }
    }
</script>
</html>

